package mylab.starters.uuid.config.mysql;

import lombok.RequiredArgsConstructor;
import mylab.starters.uuid.config.UuidAutoConfiguration;
import mylab.starters.uuid.config.UuidProperties;
import mylab.starters.uuid.impl.mysql.MysqlUuidTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@AutoConfigureAfter(UuidAutoConfiguration.class)
@ConditionalOnProperty(value = MysqlUuidAutoConfiguration.PREFIX, havingValue = "true")
public class MysqlUuidAutoConfiguration {

    static final public String PREFIX = UuidProperties.PREFIX + ".mysql.enabled";

    final private UuidProperties properties;

    @Bean
    @ConditionalOnMissingBean
    public MysqlUuidTemplate template() {
        return new MysqlUuidTemplate(properties.getMysql());
    }
}
